import 'package:flutter/material.dart';

typedef OnRegionChanged = void Function(String region);

class ReginDropDownButton extends StatefulWidget {
  OnRegionChanged onRegionChanged;
  String currentHint;

  ReginDropDownButton({super.key, required this.onRegionChanged, this.currentHint = "cn-shanghai"});

  @override
  _ReginDropDownButtonState createState() => _ReginDropDownButtonState();
}

class _ReginDropDownButtonState extends State<ReginDropDownButton> {
  List<DropdownMenuItem> getItemList() {
    List<DropdownMenuItem> items = [];
    DropdownMenuItem item1 = const DropdownMenuItem(
      value: "cn-shanghai",
      child: Text("cn-shanghai"),
    );
    DropdownMenuItem item2 = const DropdownMenuItem(
      value: "ap-southeast-1",
      child: Text("ap-southeast-1"),
    );
    DropdownMenuItem item3 = const DropdownMenuItem(
      value: "ap-northeast-1",
      child: Text("ap-northeast-1"),
    );
    DropdownMenuItem item4 = const DropdownMenuItem(
      value: "cn-beijing",
      child: Text("cn-beijing"),
    );
    items.add(item1);
    items.add(item2);
    items.add(item3);
    items.add(item4);
    return items;
  }

  @override
  Widget build(BuildContext context) {
    return DropdownButton(
        items: getItemList(),
        isExpanded: true,
        hint: Text(widget.currentHint),
        onChanged: (value) {
          setState(() {
            widget.currentHint = value;
            widget.onRegionChanged(value);
          });
        });
  }
}
